package personal.pyramid;

import java.io.*;
import java.awt.*;
import javax.swing.*;
import personal.common.Utils;

public class DrawPyramid extends Canvas
{
    private static int BRICKS_IN_BASE;  // Number of bricks in the base of the pyramid
    private static int BRICK_WIDTH;   //Width of each brick in pixels
    private static int BRICK_HEIGHT;  // Height of each brick in pixels

    public DrawPyramid(int aNumber,int aWidth,int aHeight)
    {
	if ( aNumber > 0 ) BRICKS_IN_BASE = aNumber; else BRICKS_IN_BASE = 14;
	if ( aWidth > 0 ) BRICK_WIDTH = aWidth; else BRICK_WIDTH = 30;
	if (aHeight > 0 ) BRICK_HEIGHT = aHeight; else BRICK_HEIGHT = 12;
    }

    public void paint(Graphics g)
    {

	int screen_x = BRICK_WIDTH * BRICKS_IN_BASE + 40;
	int screen_y = BRICK_HEIGHT * BRICKS_IN_BASE + 80;

	for (int i = 0; i < BRICKS_IN_BASE; ++i)
	{
	    for (int y = 0; y < (BRICKS_IN_BASE - i); ++y)
		g.drawRect((20 + y * BRICK_WIDTH + i * BRICK_WIDTH * 1/2), (screen_y - BRICK_HEIGHT * i), BRICK_WIDTH, BRICK_HEIGHT);
	}

    }
	
    public static void main(String args[])
    {
	int no_of_bricks, brick_width, brick_height;

	no_of_bricks = Utils.readValidateInteger("How many bricks in the base ??", "Error encountered while reading NUMBER of bricks...");
	brick_width = Utils.readValidateInteger("What is the width of the brick ??", "Error encountered while reading WIDTH of the brick...");
	brick_height = Utils.readValidateInteger("And the height of the brick ??", "Error encountered while reading HEIGHT of the brick...");

	DrawPyramid pyramid = new DrawPyramid(no_of_bricks, brick_width, brick_height);
	JFrame frame = new JFrame();
	frame.setTitle("A Very Basic Pyramid");
	frame.setSize((BRICK_WIDTH * BRICKS_IN_BASE + 40), (BRICK_HEIGHT * BRICKS_IN_BASE + 150));
	frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	frame.getContentPane().add(pyramid);
	frame.setVisible(true);
    }
}
